package com.example.chapter7.util;

import java.sql.Connection;
import java.sql.DriverManager;

public class DBconnection {
    private String FileName;
    private  int DBTyoe;
    private Connection conn;
    private String MYSQLDriver;
    private  String MYSQLURL;
    public  DBconnection(){
        conn = null;
    }
    public Connection getConn(){
        DBTyoe = 1;
        switch (DBTyoe){
            case 1:
                return  (getConnTOMysql());
            default:return null;
        }
    }
    public  Connection getConnTOMysql(){
        try {
            MYSQLDriver = "com.mysql.cj.jdbc.DRIVER";
            MYSQLURL =
                    "jdbc:mysql://localhost:3306/sky?user=root&password=123456"+
                    "&Unicode=true&characterEncoding=utf8";
            Class.forName(MYSQLDriver).newInstance();
            conn = DriverManager.getConnection(MYSQLURL);

        }catch (Exception e){
            e.printStackTrace();
        }
        return conn;
    }
}
